package com.njym.java.security.app.rest;

import com.njym.java.security.app.biz.FamilyTreeBiz;
import com.njym.java.security.app.entity.FamilyTree;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("familyTree")
public class FamilyTreeController extends BaseController<FamilyTreeBiz,FamilyTree> {

    @RequestMapping(value = "/add",method = RequestMethod.GET)
    @ResponseBody
    public Object addPhotos(@RequestParam String attr1, @RequestParam String attr2) {
        if (!attr2.equals("undefined")) {
            FamilyTree entity = new FamilyTree();
            entity.setAttr1(attr1);
            entity.setAttr2(Integer.parseInt(attr2));
            baseBiz.insertSelective(entity);
            return new ObjectRestResponse<>().rel(true);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }

    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Object getList(@RequestParam String attr2) {
        if (!attr2.equals("undefined")) {
            FamilyTree entity = new FamilyTree();
            entity.setAttr2(Integer.parseInt(attr2));
            List<FamilyTree> list = baseBiz.selectList(entity);
            Map<String, Object> data = new HashMap<>(1);
            data.put("list", list);
            return new ObjectRestResponse<>().rel(true).data(data);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }

    }

}